#ifndef _MESH
#define _MESH

#include "base.h"
#include "vector.h"
#include "sphere.h"

// possible filetypes for mesh loading
#define MESH_TYPE_OBJ 1 // Wavefront OBJ

typedef struct
{
  tNode *t;             // translation array
  mesh  *m;             // actual mesh pointer
} meshCollection;

typedef struct
{
  tNode   t;            // translation
  
  uint    count;        // number of subMeshes
  subMesh *content;     // pointer to mesh structures
  
  int     displayList;  // generated Display-List index (-1 for invalid)
} mesh;

// mesh structure -> triangles ONLY
typedef struct
{
  tNode   t;            // translation
  char    *description; // description string of the mesh

  vector  *v;           // vertices
  vector  *n;           // normals
  fNumber *uv;          // UV coordinates

  uint    faces;        // triangles of the mesh
  int     *f;           // triangle face indicies ([v/n/uv], -1 for invalid)
} subMesh;

// add a mesh position as renderable instance to the meshCollection
void meshAddInstance(meshCollection *c, tNode *t);

// universal mesh loader call -> loads a mesh unitized to [boundingSphere:1.0f]
bool meshLoad       (char *filename, mesh *dst, ui32 meshtype);

// -------------------------------------------------------------------
// POSSIBLY PRIVATE
void meshClear(mesh *m);

// generate hard face normals and average them by given angle
bool meshCalculateNormals(mesh *dst, fNumber angle);

// calculate the bounding sphere of a mesh/it's subMeshes
bool meshCalculateBoundingSphere(mesh *dst);
// -------------------------------------------------------------------

void

#endif // _MESH
